﻿<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:pe="http://primefaces.org/ui/extensions"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	template="/template/main.xhtml">
	<ui:define name="body">
		<h:form prependId="false">
			<p:fieldset legend="#{messages['movimento.label']}" toggleable="false" >
			
				<h:messages id="msgMovimento"/>
				<p:focus context="fields"/>
				<h:panelGrid id="fields" columns="3">
					 
					<h:outputLabel value="#{messages['movimento.label.lancamento']}: "
						for="lancamento" styleClass="text-input" />
					<p:calendar id="lancamento"
						value="#{movimentoEditMB.bean.lancamento}" disabled="true"
						pattern="dd/MM/yyyy HH:mm:ss" navigator="true"
						showButtonPanel="true" locale="#{currentLocale}"
						title="#{messages['movimento.alt.lancamento']}" />
					<p:message for="lancamento" />

					<h:outputLabel value="#{messages['movimento.label.valor']}: "
						for="valor" styleClass="text-input" />
					<pe:inputNumber id="valor" value="#{movimentoEditMB.bean.valor}" 
						tabindex="1" required="true" 
						title="#{messages['movimento.alt.valor']}" />
					<p:message for="valor" />

					<h:outputLabel value="#{messages['movimento.label.cliente']}: "
						for="cliente" styleClass="text-input" />
					<p:inputText id="cliente" value="#{movimentoEditMB.codigoCliente}"
						tabindex="2" required="true"
						disabled="#{not empty movimentoEditMB.bean.cliente}"
						valueChangeListener="#{movimentoEditMB.buscaCliente}"
						title="#{messages['movimento.alt.cliente']}" onblur="submit()" >
					</p:inputText>
					<h:outputText value="#{movimentoEditMB.bean.cliente.nome}" />

				</h:panelGrid>
			</p:fieldset>
			<p:toolbar>
				<p:toolbarGroup align="left">
					<p:commandButton value="#{messages['button.save']}" onclick="loginDlg.show()"
						rendered="#{not empty movimentoEditMB.bean.cliente.senha}" />
					<p:commandButton value="#{messages['button.save']}" onclick="changeDlg.show()"
						rendered="#{not empty movimentoEditMB.bean.cliente and empty movimentoEditMB.bean.cliente.senha}" />
				</p:toolbarGroup>
			</p:toolbar>
			
			<p:dialog id="loginDialog" modal="true" header="Informe a Senha" widgetVar="loginDlg">
				<h:messages id="msgLogin"/>
				<h:panelGrid columns="2">
					<h:outputLabel value="#{messages['cliente.label.senha']}: "
						for="senha" styleClass="text-input" />
					<p:password id="senha" value="#{movimentoEditMB.senhaCliente}" />
					<f:facet name="footer">  
		                <p:commandButton id="loginButton" value="Confirmar" update="msgLogin fields"
		                    actionListener="#{movimentoEditMB.logarCliente}" process="@this senha"
		                    tabindex="3" oncomplete="handleLoginRequest(xhr, status, args)"/>  
		            </f:facet>
				</h:panelGrid>
			</p:dialog>
			
			<p:dialog id="changeDialog" modal="true" header="#{messages['label.confirm.changepass']}" widgetVar="changeDlg">
				<h:messages id="msgSenhas"/>
				<h:panelGrid columns="2">
					<h:outputLabel value="Digite a Nova Senha:*" for="senhaNova" />
					<p:password id="senhaNova" value="#{movimentoEditMB.senhaCliente}" match="repitaSenha"/>
					<h:outputLabel value="Repita a Nova Senha:*" for="repitaSenha" />
					<p:password id="repitaSenha" value="#{movimentoEditMB.senhaCliente}"/>
					<f:facet name="footer">
						<p:commandButton id="mudarSenha" value="Confirmar" update="msgLogin fields" 
							actionListener="#{movimentoEditMB.alterarSenha}"
							oncomplete="handleChangeRequest(xhr, status, args)"/>
					</f:facet>
				</h:panelGrid>
			</p:dialog>
		</h:form>
		<script type="text/javascript">  
		    function handleLoginRequest(xhr, status, args) {  
		        if(args.validationFailed || !args.loggedIn) {  
		        	loginDlg.jq.effect("shake", { times:5 }, 100);  
		        }   
		        else {  
		        	loginDlg.hide();  
		        }  
		    }  
		    function handleChangeRequest(xhr, status, args) {  
		        if(args.validationFailed || !args.loggedIn) {  
		        	changeDlg.jq.effect("shake", { times:5 }, 100);  
		        }   
		        else {  
		        	changeDlg.hide();  
		        }  
		    }  
		</script>  
	</ui:define>
</ui:composition>